home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: news.csra.net!not-for-mail
- From: "Robert S. Stull" <stullr@dinamero.com>
- Subject: Re: Q: Returning a reference
- Message-ID: <30F53184.C57@dinamero.com>
- Date: Thu, 11 Jan 1996 10:49:24 -0500
- Organization: Ipswitch, Inc.
- X-Mailer: Mozilla 2.0b4 (WinNT; I)
- MIME-Version: 1.0
- CC: stullr-news@dinamero.com
- References: <4cvsm2$5ig@dub-news-svc-4.compuserve.com>
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
-
- Martin Aupperle wrote:
- >
- > Borland C++ V4.5 does not allow to return a reference to a local
- > variable:
- >
- > int &doIt() {
- >
- > int i = 7;
- > return i; // syntax error
- > }
- >
- > I remember that I once had a compiler that did allow it (it gave me
- > only a warning).
- > Which one is right? I think that it should be an error because after
- > the function has terminated, the reference has no data object it is
- > bound to any more.
- >
- > Martin
- >
- > -----------------------------------
- > Signatures are a waste of bandwidth
- > -----------------------------------
-
- Try this:
- static int i = 7;
- Most compilers allow it and it will still be valid when you exit
- the function.
-
- Bob
- --
- Robert S. Stull
- Net Fool
- "Will work for food." - NOT!!!!! "Will work for sex."
- - NOT!!!
- "Won't work for anything." -- THAT'S IT! YES! YES! THAT'S
- MEEEE!!!
-
-